#!/usr/bin/env python
# -*- coding: utf-8 -*-
# @Time    : 2024/3/25 16:18
# @Author : 闫峰
# @File    : allegro.py
from common.setting import ensure_path_sep
from utils.mysqlUtils.db_pool import Database
from utils.logging_tool.init_logger import init_logger
from utils.mysqlUtils.mongodb_utils import MongoDBLink
from utils.noticeUtils.dingtalkControl import DingTalkSendMsg
from utils.otherutils.MyThreadPool import MyThreadPool

INFO, ERROR, WARNING = init_logger()


class Test:
    product_db = Database(ensure_path_sep("\\config\\shopeev2_config.yaml.bak"), "HWY-ZH-GZ-RDS-Product")
    zhcxkj_center_listing_comprehensive_db = Database(ensure_path_sep("\\config\\shopeev2_config.yaml.bak"),
                                                      "zhcxkj_center_listing_comprehensive")
    zhcxkj_center_strategy_comprehensive_db = Database(ensure_path_sep("\\config\\shopeev2_config.yaml.bak"),
                                                       "HWY-ZH-GZ-RDS-strategy")
    db_java_test = Database(ensure_path_sep("\\config\\shopeev2_config.yaml.bak"), "test_jdw_database")

    t_allegro_strategy_adjust_price_detail = MongoDBLink(
        uri='mongodb://reader:Vly07YmbY0kLt80Y?@121.37.240.172:8635,121.37.230.118:8635/test?authSource=admin&replicaSet=replica',
        dbname='zhcxkj_center_strategy', coll_name="t_allegro_strategy_adjust_price_detail")
    def test__(self,strategy_id):
        # 查询有效的条件策略
        get_strategy_id_list = """
        select id
from zhcxkj_center_strategy_comprehensive.t_allegro_marketing_strategy
where strategy_type=5
and  status =1
and id = 32
        """
        strategy_id_list = self.zhcxkj_center_strategy_comprehensive_db.fetch_all_tuple(get_strategy_id_list,())
        if not len(strategy_id_list):
            return
        for strategy_id in strategy_id_list:
            # paginate = [
            #   { "$match": { "strategyId": strategy_id[0] } },
            #   { "$group": { "_id": "$status", "count": { "$sum": 1 } } }
            # ]
            # res = self.t_allegro_strategy_adjust_price_detail.aggregate(paginate)
            res = [{'_id': 1, 'count': 1}, {'_id': 2, 'count': 50}, {'_id': 0, 'count': 147546}]
            res_map = {item['_id']: item['count'] for item in res}

            model ={
                0:res_map.get(0,0),
                1:res_map.get(1,0),
                2:res_map.get(2,0),
                3:res_map.get(3,0),
                4:res_map.get(4,0),
                5:res_map.get(5,0)
            }
            print()
            # 查询策略执行情况

if __name__ == '__main__':
    Test().test__(32)